package com.linux4fun.singleton;

/**
 *
 * 线程安全的单例模式（块级别的同步锁）
 * https://kylepeng93.github.io
 *
 * @author pengkai
 * @date 2021-03-21 下午9:22
 */
public class ThreadSafeSingletonBlock {
    private static ThreadSafeSingletonBlock instance;

    private ThreadSafeSingletonBlock() {}

    public static ThreadSafeSingletonBlock getInstance() {
        if (instance == null) {
            synchronized (ThreadSafeSingletonBlock.class) {
                if (instance == null) {
                    instance = new ThreadSafeSingletonBlock();
                }
            }
        }
        return instance;
    }
}
